{% extends 'base.html' %}

{% block title %}添加碳盘查目录{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h4 class="mb-0">添加碳盘查目录</h4>
            </div>
            <div class="card-body">
                <form method="post">
                    <div class="mb-3">
                        <label for="name" class="form-label">目录名称 <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="name" name="name" required>
                    </div>
                    
                    <div class="mb-3">
                        <label for="parent_id" class="form-label">父目录</label>
                        <select class="form-select" id="parent_id" name="parent_id">
                            <option value="0">-- 无父目录 (顶级目录) --</option>
                            {% if parents and parents|length > 0 %}
                                {% for parent in parents %}
                                    {% if parent.level < 5 %}
                                    <option value="{{ parent.id }}">{{ '　' * (parent.level - 1) }}|-- {{ parent.name }} (层级: {{ parent.level }})</option>
                                    {% endif %}
                                {% endfor %}
                            {% else %}
                                <option value="0" disabled>暂无可用父分类</option>
                            {% endif %}
                        </select>
                        <div class="form-text">最多支持5级分类，选择父目录后将自动计算当前层级</div>
                    </div>
                    
                    <div class="d-flex justify-content-between">
                        <a href="{{ url_for('inventory_category.category_list') }}" class="btn btn-secondary">取消</a>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}